// 1- ip
//    本机：http://127.0.0.1:8090
//    本机：http://localhost:8090
//    局域网：http://192.168.46.23:8090
// 2- hosts:   27.0.0.1  zhangpeiyue.com
//    http://zhangpeiyue.com:8090
const http = require("http");
const url = require("url");
const fs = require("fs");
const path = require("path");
const server = http.createServer((req,res)=>{
	let {pathname} = url.parse(req.url);
	if(pathname === "/") pathname = "/weibo.html"
	// 方案一：
	// if(pathname === "/weibo.html" || pathname === "/style/weibo.css" || pathname === "/img/takeSbmComment.png" || pathname === "/img/icons.png"){
	// 	fs.readFile(path.join(__dirname,"./html",pathname),(err,result)=>{
	// 		res.end(result);
	// 	})
	// }else {
	// 	res.setHeader("Content-Type","text/html;charset=utf-8");
	// 	res.end("404，不存在");
	// }
	
	// 方案二
	const pathArr = [
		"/weibo.html",
		"/style/weibo.css",
		"/img/takeSbmComment.png",
		"/img/icons.png"
	]
	if(pathArr.includes(pathname)){
		fs.readFile(path.join(__dirname,"./html",pathname),(err,result)=>{
			res.end(result);
		})
	}else {
		res.setHeader("Content-Type","text/html;charset=utf-8");
		res.end("404，不存在");
	}
});
server.listen(8091,()=>{
	console.log("success");
})